package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.XzkClass;
import com.ruoyi.system.service.IXzkClassService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 班级Controller
 * 
 * @author ruoyi
 * @date 2021-04-01
 */
@Controller
@RequestMapping("/system/Class")
public class XzkClassController extends BaseController
{
    private String prefix = "system/Class";

    @Autowired
    private IXzkClassService xzkClassService;

    @RequiresPermissions("system:Class:view")
    @GetMapping()
    public String Class()
    {
        return prefix + "/Class";
    }

    /**
     * 查询班级列表
     */
    @RequiresPermissions("system:Class:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(XzkClass xzkClass)
    {
        startPage();
        List<XzkClass> list = xzkClassService.selectXzkClassList(xzkClass);
        return getDataTable(list);
    }

    /**
     * 导出班级列表
     */
    @RequiresPermissions("system:Class:export")
    @Log(title = "班级", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(XzkClass xzkClass)
    {
        List<XzkClass> list = xzkClassService.selectXzkClassList(xzkClass);
        ExcelUtil<XzkClass> util = new ExcelUtil<XzkClass>(XzkClass.class);
        return util.exportExcel(list, "Class");
    }

    /**
     * 新增班级
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存班级
     */
    @RequiresPermissions("system:Class:add")
    @Log(title = "班级", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(XzkClass xzkClass)
    {
        return toAjax(xzkClassService.insertXzkClass(xzkClass));
    }

    /**
     * 修改班级
     */
    @GetMapping("/edit/{className}")
    public String edit(@PathVariable("className") Integer className, ModelMap mmap)
    {
        XzkClass xzkClass = xzkClassService.selectXzkClassById(className);
        mmap.put("xzkClass", xzkClass);
        return prefix + "/edit";
    }

    /**
     * 修改保存班级
     */
    @RequiresPermissions("system:Class:edit")
    @Log(title = "班级", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(XzkClass xzkClass)
    {
        return toAjax(xzkClassService.updateXzkClass(xzkClass));
    }

    /**
     * 删除班级
     */
    @RequiresPermissions("system:Class:remove")
    @Log(title = "班级", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(xzkClassService.deleteXzkClassByIds(ids));
    }
}
